(function () {
    angular.module('app')
        .component('xxRegister', {
            templateUrl: '/app/common/register/register.html',
            controller: ctrl
        });

    function ctrl($scope,$state,$mdDialog,urlCnst,RegisterFactory,util) {
        $scope.status = '  ';
        $scope.customFullscreen = false;
        $scope.user = {
            username:"",
            password:"",
            realName:'',
            phone:"",
        };
        $scope.trueUsername = true;
        $scope.truePwd = true;
        $scope.truePhone = true;

        $scope.register = function (body) {
            $scope.trueUsername = util.testUsername(body['username']);
            $scope.truePwd = util.testUsername(body['password']);
            $scope.truePhone = util.testPhone(body['phone']);

            if(!body['username']||!body['password'] ||!body['phone']){
                urlCnst.notice('请将信息填写完整');
                return;
            }
            if ( !$scope.trueUsername || !$scope.truePwd || !$scope.truePhone) {
                console.log('fa');
                return;
            }
            function cb(err,res) {
                if(!err)urlCnst.notice('注册成功');
                console.log('suc')
            }
            RegisterFactory.register(body,cb);
        };

        $scope.login = function () {
            $state.go('login')
        }
    }
})();
